package com.mz.nhoz.xlsx;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/**
 * Registro de xlsx.
 * 
 * @author martin
 *
 */
public class XlsxRecord {
	private RecordDataMap recordDataMap = new RecordDataMap();

	public XlsxRecord(XlsxCell... xlsxCells) {
		set(xlsxCells);
	}

	private void set(XlsxCell... xlsxCells) {
		for (int i = 0; i < xlsxCells.length; i++) {
			XlsxCell xlsxCell = xlsxCells[i];

			XlsxTableHeader header = xlsxCell.getHeader();
			Object value = xlsxCell.getValue();

			recordDataMap.put(header, value);
		}
	}

	public XlsxRecord(List<XlsxCell> cellList) {
		XlsxCell[] cellArray = new XlsxCell[cellList.size()];
		int i = 0;
		for (XlsxCell xlsxCell : cellList) {
			cellArray[i++] = xlsxCell;
		}

		set(cellArray);
	}

	/**
	 * Retorna un valor dentro del registro a partir del nombre del encabezado
	 * de dato correspondiente.
	 * 
	 * @param headerName
	 *            - Nombre de encabezado del dato del registro.
	 * @return valor dentro del registro a partir del nombre del encabezado de
	 *         dato correspondiente.
	 */
	public Object get(String headerName) {
		return recordDataMap.getFromHeaderName(headerName);
	}

	public Object get(XlsxTableHeader header) {
		return recordDataMap.get(header);
	}

	public Collection<Object> getValues() {
		return recordDataMap.values();
	}

	public String toString() {
		return Arrays.toString(getValues().toArray());
	}
}// XlsxRecord
